package mest.util;

import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import lombok.Data;
import mest.entity.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 *@Title mestUtil.java
 *@description TODO
 *@time 2019年12月15日 下午5:42:40
 *@author Twinson Wong
 **/

public class mestUtil {


    /**
	 * 根据request获取客户数据库
	 * @param request
	 * @return
	 */
	public static String getCompanyDB(HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        return user.getTheirDb();
    }

    /**
     * 根据request获取客户数据库
     * @param request
     * @return
     */
    public static Integer getUserId(HttpServletRequest request) {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        return user.getUserId();
    }

    /**
     * 判断整数（int）
     * @param str
     * @return
     */
    public static boolean isInteger(String str) {
        if (null == str || "".equals(str)) {
            return false;
        }
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }
      
    /**
     * 判断浮点数（double和float）
     * @param str
     * @return
     */
    public static boolean isDouble(String str) {
        if (null == str || "".equals(str)) {
            return false;
        }
        Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$");
        return pattern.matcher(str).matches();
    }
}
